#include "CLTConnection.h"
#include <iostream>
#include <string>


CLTConnection::CLTConnection(boost::asio::io_service& io_service) : mySocket(io_service)
{
//	boost::asio::socket_base::keep_alive option(true);
//	mySocket.set_option(option);
}


boost::asio::ip::tcp::socket& CLTConnection::GetSocket()
{
	return mySocket;
}

/*
void CLTConnection::Write()
{

	boost::asio::async_write(mySocket,boost::asio::buffer(thesize),boost::bind(&CLTConnection::handle_write,this,boost::asio::placeholders::error,boost::asio::placeholders::bytes_transferred));

	boost::asio::async_write(mySocket,boost::asio::buffer(output),boost::bind(&CLTConnection::handle_write,this,boost::asio::placeholders::error,boost::asio::placeholders::bytes_transferred));

}
*/

void CLTConnection::Write(std::string input)
{
	boost::asio::async_write(mySocket,boost::asio::buffer(input),boost::bind(&CLTConnection::handle_write,shared_from_this(),boost::asio::placeholders::error,boost::asio::placeholders::bytes_transferred));
}


void CLTConnection::Write(std::vector<char> *input)
{
	boost::asio::async_write(mySocket,boost::asio::buffer((*input)),boost::bind(&CLTConnection::handle_write,shared_from_this(),boost::asio::placeholders::error,boost::asio::placeholders::bytes_transferred));
}


void CLTConnection::Read()
{
	/* not implemented yet :) */
}


void CLTConnection::handle_write(const boost::system::error_code &er, std::size_t send)
{
	if(er)
	{
        std::cout << er.message() << std::endl;
	}
	else
	{
		std::cout << "writen: " << send << std::endl;
	}
}
